package com.portal.framework.util;

import java.io.IOException;

import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;

/**
 * 资源工具类,封装了一些spring资源相关的方法
 * @author 卢烁波
 * @date 2007-3-10
 */
public final class ResourceUtil {
	private ResourceUtil() {
	}

	public static Resource[] getClassPathResource(String locationPattern) {
		ResourcePatternResolver rpr = new PathMatchingResourcePatternResolver();
		try {
			return rpr.getResources(locationPattern);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return new Resource[0];
	}

	public static Resource[] getClassPathResource(String locationPattern,
			ClassLoader classLoader) {
		ResourcePatternResolver rpr = new PathMatchingResourcePatternResolver(
				classLoader);
		try {
			return rpr.getResources(locationPattern);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return new Resource[0];
	}

}
